Quick Index
Overview


The Express web framework and EJS templating engine are two powerful pieces of the Node.js web programming stack. The goal of this project is to get familiar with them.

Before Starting


Before starting this project, if you want to ensure your understanding of a URL relative to web programming, then go here...

Guide Examples for Project


SubjectStep-By-Step
Example
Book
Reference
Creating web serverCreating Web Server in ExpressLesson 8
Adding a controllerAdding Controller in ExpressLesson 9
Adding middlewareAdding Middleware in ExpressListing 9.4
RoutingRouting in ExpressLesson 9
Using templating engineUsing EJS Templating EngineLesson 10

Notes:

We'll be creating source files with different extensions ("js", "ejb", etc). These are all plain text files. Here is a note on saving with different extensions.

Also, here is a link to Assignment "Node1" (Core Concepts Drills).

Problem Approach


It is coder's choice as to how the problem is approached, -- you only need to complete one project. The step-by-step examples allow for incremental learning. But you do not need to hand in five projects. Just the one listed in "Project Specs" below.

Many of the terms used here will be new. They are explained in the examples.

Please feel free to customize any of the greetings and web page content used in the examples for your project!

Project Specs



Create a Web Server


Create a web server using the Express web framework.

Use Controllers


Put the callback function code for the routes into a controller, in a file with this relative project path:

controllers/home-controller.js


Add Middleware


Add middleware using the Express framework support for middleware.

The middleware should log (print) the request url path to the console. E.g., something like:

request received in middleware
url path and query: /items/beets


Support Multiple Routes


Support three or more routes on the web server. Each route should have its own controller (callback) function (all in file "controllers/home-controller.js")

Note that the next section "Use EJS Template Engine" provides info pertinent to this section.

We'll now describe the three routes to code:

Home Route


A home URL "http://localhost:3000/" should produce a web browser page like:

Greetings from the web server
Thu Mar 25 2021 14:03:47 GMT-0500 (Central Daylight Time)


Here is the js to get a date and time string:

(new Date()).toString()


Even better (optional but good fun):


Vegetable Name Route


The route
 "items/<vegetable-name>"
uses a dynamic parameter "vegetable-name". E.g., URL "http://localhost:3000/items/kale" should produce a web browser page like:

Yummy kale!
Plus any HTML to beautify the web page (coder's choice)
plus show more dynamic content like date, etc (coder's choice)


URL "http://localhost:3000/items/beets" should produce a web browser page like:

Just like "kale" above except for this difference:

Yummy beets!
...


Coder's Choice Route


Add another web page for a route with a dynamic parameter similar to
 "items/<vegetable-name>"
above

Use EJS Template Engine


The web server should use the EJS templating engine to produce the web pages described in the previous "routing" section.

Put EJS (extension ".ejs") files into project sub-directory "views".

The EJS Files:

URLDescriptionProject Relative File Path
home routehome pageviews/index.ejs
vegetable name routeveggie pageviews/veg-page.ejs
coder's choice routecoder's choicecoder's choice


Submitting